package com.wujilee.wujileemybatisdynamicsql.mapper;

import static com.wujilee.wujileemybatisdynamicsql.mapper.RolesDynamicSqlSupport.*;
import static org.mybatis.dynamic.sql.SqlBuilder.isEqualTo;

import com.wujilee.wujileemybatisdynamicsql.entity.Roles;
import java.util.Collection;
import java.util.List;
import java.util.Optional;
import javax.annotation.Generated;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.type.JdbcType;
import org.mybatis.dynamic.sql.BasicColumn;
import org.mybatis.dynamic.sql.delete.DeleteDSLCompleter;
import org.mybatis.dynamic.sql.select.CountDSLCompleter;
import org.mybatis.dynamic.sql.select.SelectDSLCompleter;
import org.mybatis.dynamic.sql.select.render.SelectStatementProvider;
import org.mybatis.dynamic.sql.update.UpdateDSL;
import org.mybatis.dynamic.sql.update.UpdateDSLCompleter;
import org.mybatis.dynamic.sql.update.UpdateModel;
import org.mybatis.dynamic.sql.util.SqlProviderAdapter;
import org.mybatis.dynamic.sql.util.mybatis3.CommonCountMapper;
import org.mybatis.dynamic.sql.util.mybatis3.CommonDeleteMapper;
import org.mybatis.dynamic.sql.util.mybatis3.CommonInsertMapper;
import org.mybatis.dynamic.sql.util.mybatis3.CommonSelectMapper;
import org.mybatis.dynamic.sql.util.mybatis3.CommonUpdateMapper;
import org.mybatis.dynamic.sql.util.mybatis3.MyBatis3Utils;

@Mapper
public interface RolesMapper extends CommonSelectMapper, CommonCountMapper, CommonDeleteMapper, CommonInsertMapper<Roles>, CommonUpdateMapper {
    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2025-05-03T18:00:34.836+08:00", comments="Source Table: sys_role")
    BasicColumn[] selectList = BasicColumn.columnList(roleId, name, description, createBy, updateBy, createTime, updateTime);

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2025-05-03T18:00:34.835+08:00", comments="Source Table: sys_role")
    @SelectProvider(type=SqlProviderAdapter.class, method="select")
    @Results(id="RolesResult", value = {
        @Result(column="role_id", property="roleId", jdbcType=JdbcType.BIGINT, id=true),
        @Result(column="name", property="name", jdbcType=JdbcType.VARCHAR),
        @Result(column="description", property="description", jdbcType=JdbcType.VARCHAR),
        @Result(column="create_by", property="createBy", jdbcType=JdbcType.VARCHAR),
        @Result(column="update_by", property="updateBy", jdbcType=JdbcType.VARCHAR),
        @Result(column="create_time", property="createTime", jdbcType=JdbcType.BIGINT),
        @Result(column="update_time", property="updateTime", jdbcType=JdbcType.BIGINT)
    })
    List<Roles> selectMany(SelectStatementProvider selectStatement);

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2025-05-03T18:00:34.835+08:00", comments="Source Table: sys_role")
    @SelectProvider(type=SqlProviderAdapter.class, method="select")
    @ResultMap("RolesResult")
    Optional<Roles> selectOne(SelectStatementProvider selectStatement);

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2025-05-03T18:00:34.835+08:00", comments="Source Table: sys_role")
    default long count(CountDSLCompleter completer) {
        return MyBatis3Utils.countFrom(this::count, roles, completer);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2025-05-03T18:00:34.835+08:00", comments="Source Table: sys_role")
    default int delete(DeleteDSLCompleter completer) {
        return MyBatis3Utils.deleteFrom(this::delete, roles, completer);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2025-05-03T18:00:34.836+08:00", comments="Source Table: sys_role")
    default int deleteByPrimaryKey(Long roleId_) {
        return delete(c -> 
            c.where(roleId, isEqualTo(roleId_))
        );
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2025-05-03T18:00:34.836+08:00", comments="Source Table: sys_role")
    default int insert(Roles row) {
        return MyBatis3Utils.insert(this::insert, row, roles, c ->
            c.map(roleId).toProperty("roleId")
            .map(name).toProperty("name")
            .map(description).toProperty("description")
            .map(createBy).toProperty("createBy")
            .map(updateBy).toProperty("updateBy")
            .map(createTime).toProperty("createTime")
            .map(updateTime).toProperty("updateTime")
        );
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2025-05-03T18:00:34.836+08:00", comments="Source Table: sys_role")
    default int insertMultiple(Collection<Roles> records) {
        return MyBatis3Utils.insertMultiple(this::insertMultiple, records, roles, c ->
            c.map(roleId).toProperty("roleId")
            .map(name).toProperty("name")
            .map(description).toProperty("description")
            .map(createBy).toProperty("createBy")
            .map(updateBy).toProperty("updateBy")
            .map(createTime).toProperty("createTime")
            .map(updateTime).toProperty("updateTime")
        );
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2025-05-03T18:00:34.836+08:00", comments="Source Table: sys_role")
    default int insertSelective(Roles row) {
        return MyBatis3Utils.insert(this::insert, row, roles, c ->
            c.map(roleId).toPropertyWhenPresent("roleId", row::getRoleId)
            .map(name).toPropertyWhenPresent("name", row::getName)
            .map(description).toPropertyWhenPresent("description", row::getDescription)
            .map(createBy).toPropertyWhenPresent("createBy", row::getCreateBy)
            .map(updateBy).toPropertyWhenPresent("updateBy", row::getUpdateBy)
            .map(createTime).toPropertyWhenPresent("createTime", row::getCreateTime)
            .map(updateTime).toPropertyWhenPresent("updateTime", row::getUpdateTime)
        );
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2025-05-03T18:00:34.836+08:00", comments="Source Table: sys_role")
    default Optional<Roles> selectOne(SelectDSLCompleter completer) {
        return MyBatis3Utils.selectOne(this::selectOne, selectList, roles, completer);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2025-05-03T18:00:34.836+08:00", comments="Source Table: sys_role")
    default List<Roles> select(SelectDSLCompleter completer) {
        return MyBatis3Utils.selectList(this::selectMany, selectList, roles, completer);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2025-05-03T18:00:34.836+08:00", comments="Source Table: sys_role")
    default List<Roles> selectDistinct(SelectDSLCompleter completer) {
        return MyBatis3Utils.selectDistinct(this::selectMany, selectList, roles, completer);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2025-05-03T18:00:34.836+08:00", comments="Source Table: sys_role")
    default Optional<Roles> selectByPrimaryKey(Long roleId_) {
        return selectOne(c ->
            c.where(roleId, isEqualTo(roleId_))
        );
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2025-05-03T18:00:34.836+08:00", comments="Source Table: sys_role")
    default int update(UpdateDSLCompleter completer) {
        return MyBatis3Utils.update(this::update, roles, completer);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2025-05-03T18:00:34.836+08:00", comments="Source Table: sys_role")
    static UpdateDSL<UpdateModel> updateAllColumns(Roles row, UpdateDSL<UpdateModel> dsl) {
        return dsl.set(roleId).equalTo(row::getRoleId)
                .set(name).equalTo(row::getName)
                .set(description).equalTo(row::getDescription)
                .set(createBy).equalTo(row::getCreateBy)
                .set(updateBy).equalTo(row::getUpdateBy)
                .set(createTime).equalTo(row::getCreateTime)
                .set(updateTime).equalTo(row::getUpdateTime);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2025-05-03T18:00:34.836+08:00", comments="Source Table: sys_role")
    static UpdateDSL<UpdateModel> updateSelectiveColumns(Roles row, UpdateDSL<UpdateModel> dsl) {
        return dsl.set(roleId).equalToWhenPresent(row::getRoleId)
                .set(name).equalToWhenPresent(row::getName)
                .set(description).equalToWhenPresent(row::getDescription)
                .set(createBy).equalToWhenPresent(row::getCreateBy)
                .set(updateBy).equalToWhenPresent(row::getUpdateBy)
                .set(createTime).equalToWhenPresent(row::getCreateTime)
                .set(updateTime).equalToWhenPresent(row::getUpdateTime);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2025-05-03T18:00:34.837+08:00", comments="Source Table: sys_role")
    default int updateByPrimaryKey(Roles row) {
        return update(c ->
            c.set(name).equalTo(row::getName)
            .set(description).equalTo(row::getDescription)
            .set(createBy).equalTo(row::getCreateBy)
            .set(updateBy).equalTo(row::getUpdateBy)
            .set(createTime).equalTo(row::getCreateTime)
            .set(updateTime).equalTo(row::getUpdateTime)
            .where(roleId, isEqualTo(row::getRoleId))
        );
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2025-05-03T18:00:34.837+08:00", comments="Source Table: sys_role")
    default int updateByPrimaryKeySelective(Roles row) {
        return update(c ->
            c.set(name).equalToWhenPresent(row::getName)
            .set(description).equalToWhenPresent(row::getDescription)
            .set(createBy).equalToWhenPresent(row::getCreateBy)
            .set(updateBy).equalToWhenPresent(row::getUpdateBy)
            .set(createTime).equalToWhenPresent(row::getCreateTime)
            .set(updateTime).equalToWhenPresent(row::getUpdateTime)
            .where(roleId, isEqualTo(row::getRoleId))
        );
    }
}